package com.gzy.rpsm_property.pojo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.DigestUtils;

import javax.validation.constraints.*;
import java.nio.charset.StandardCharsets;
import java.util.List;


@Data
@ApiModel(value = "用户信息，包含管理员、物业人员和住户")
public class User {
    @NotNull(message = "用户ID不能为空")
    @ApiModelProperty(value = "用户 id")
    private Integer userid;

    @Min(value = 0, message = "性别只能是0或1")
    @Max(value = 1, message = "性别只能是0或1")
    @ApiModelProperty(value = "用户性别")
    private Short gender;

    @Min(value = 1, message = "年龄必须大于等于1")
    @Max(value = 100, message = "年龄必须小于等于100")
    @ApiModelProperty(value = "用户年龄")
    private Short age;

    @Min(value = 11, message = "用户状态至少为11")
    @ApiModelProperty(value = "用户状态")
    private Short user_status;

    @PositiveOrZero(message = "房间ID不能为负数")
    @ApiModelProperty(value = "用户所属房屋id")
    private Short user_roomid;

    @ApiModelProperty(value = "身份证号")
    @Size(min = 18, max = 18, message = "身份证号必须是18位")
    private String idcard;

    @ApiModelProperty(value = "头像文件")
    private String user_avatar;

    @ApiModelProperty("用户账号")
    private String account;

    public Integer getUserid() {
        return userid;
    }

    public void setUserid(Integer userid) {
        this.userid = userid;
    }

    @ApiModelProperty("用户 token")
    private String token;
    @ApiModelProperty("用户姓名")
    private String username;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @ApiModelProperty(value = "用户类型")
    private Short user_type;

    @ApiModelProperty("用户密码")
    private String password;

    public String getPassword() {
        return password;
    }

    @ApiModelProperty(value = "用户房间信息，可能一个人有多套房")
    private List<Room> rooms;

    @Override
    public String toString() {
        return "User{" +
                "userid=" + userid +
                ", gender=" + gender +
                ", age=" + age +
                ", user_status=" + user_status +
                ", user_roomid=" + user_roomid +
                ", idcard='" + idcard + '\'' +
                ", user_avatar='" + user_avatar + '\'' +
                ", account='" + account + '\'' +
                ", token='" + token + '\'' +
                ", username='" + username + '\'' +
                ", user_type=" + user_type +
                ", password='" + password + '\'' +
                ", rooms=" + rooms +
                '}';
    }

    public void setPassword(String password) {
        if (password.length() !=32) {
            this.password = DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8));
        }else {
            this.password = password;
        }
    }



}
